﻿Imports Exp.DATA_Service
Imports Exp.Model
Imports Exp.DATA_Service.Exp.DATA_Service
Public Class ucUnitView
    Inherits System.Web.UI.UserControl
    Private _unitid As String

    Public Property UnitID() As Integer
        Get
            Return _unitid
        End Get
        Set(ByVal value As Integer)
            _unitid = value
        End Set
    End Property
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        HDFieldUnitID.Value = _unitid

        BindData()
    End Sub
    Sub BindData(Optional ByVal showUpdate As Boolean = False)
        Dim REM_Unit As New REM_Unit
        Dim Unit_Service As New Unit_Service
        REM_Unit = Unit_Service.GetByID(_unitid)
        If Not REM_Unit Is Nothing Then
            lblUnitID.Text = REM_Unit.Unit_ID
            lblUnitNumber.Text = REM_Unit.UnitName
            Dim REM_Resort As New REM_Resort
            Dim Resort_service As New Resort_service
            lblResort.Text = Resort_service.GetByID(REM_Unit.Resort_ID).ResortName
            Dim REM_UnitType As New REM_UnitType
            Dim UnitType_service As New UnitType_service
            lblUnitType.Text = UnitType_service.GetByID(REM_Unit.UnitType_ID).UnitTypeName
            lblAddress.Text = REM_Unit.Address
            lblDescription.Text = REM_Unit.Description
            Dim REM_Currency As New REM_Currency
            Dim Currency_Service As New Currency_Service
            lblCurrency.Text = Currency_Service.GetByID(REM_Unit.Currency_ID).Currency_Name
            lblAreasize.Text = REM_Unit.Sqm & " (sqr.m.)"
            lblRate.Text = REM_Unit.RatePrice.Value.ToString("#,###") & " (per night)"
            lblBookNight.Text = REM_Unit.PointPerNight.ToString("#,###") & " (per night)"
            If REM_Unit.isActive Then
                lblStatus.Text = "Active"
            Else
                lblStatus.Text = "InActive"
            End If
        End If

        If showUpdate = True Then
            Me.pnlUpdatePoolUnit.Visible = True
            Dim objOwnSV As New Owner_Service
            Dim objOwn = objOwnSV.GetByUserIDAndUnitID(0, UnitID).FirstOrDefault
            If Not objOwn.ShareStartDate Is Nothing Then Me.cldStartDateView0.SelectedDate = objOwn.ShareStartDate.Value
            If Not objOwn.ShareEndDate Is Nothing Then Me.cldEndDateView0.SelectedDate = objOwn.ShareEndDate.Value

        End If
    End Sub

    Public Function SaveShareDate(ByVal user_id As Integer) As Boolean
        Dim result As Boolean = False

        Dim startdate As DateTime = Date.ParseExact(Me.txtStartDateView0.Text.Trim, "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo)
        Dim enddate As DateTime = Date.ParseExact(Me.txtEndDateView0.Text.Trim, "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo)

        If startdate > enddate Then
            JavaScript.AlertMessage(Me.Page, "- Share start date not more than Share end date\n")
        Else
            Dim svUnit As New Owner_Service
            svUnit.UpdateShareDate(CInt(lblUnitID.Text), startdate, enddate, user_id)
            result = True
        End If

        ' Dim objunit = svUnit.GetByID(_unitid, Me.cldStartDateView0.SelectedDate, Me.cldEndDateView0.SelectedDate, )
        Return result

    End Function
End Class